<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/12/28 0028
 * Time: 22:34
 */

namespace app\index\model;
use think\Db;
use think\Model;

class User extends Model
{
    protected $autoWriteTimestamp = 'datetime';
    public function userinfo(){
        return $this->hasOne('UserInfo','user_id');
    } 

    public function user_search($data){
        $user=new User();
        $user=$user->where('username',$data)->paginate(10);
        return $user;
    }

    public function user_add($data){
        $user=new User;
        $user->username =$data['username'];
        $user->password =md5($data['password']);
        $user->email    =$data['email'];
        $user->realname =$data['realname'];
        $user->statu =1;
        $user->together(['userinfo'=>['email','realname']])->save();
        return $user;
    }
}